using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Deduplicator
{
    public partial class Form1 : Form
    {
  
        
        public Form1()
        {
            InitializeComponent();
            
        }

        public void PerformScan(TreeNode Node)
        {
            ResourceFileReader resourceFileReader = new ResourceFileReader(textBoxMusix, textBoxMovies, textBoxPictures, textBoxScanned, label6, progressBar1, pictureBox1, treeView1);
            try
            {
                if (Node.Checked)
                {
                    resourceFileReader.ScanDirectory(Node, textBox2.Text);
                }
                foreach (TreeNode node in Node.Nodes)
                    PerformScan(node);

                textBoxPictures.Text = "Moved: \t" + resourceFileReader.filecounter.MovedFiles + "\t" + " Duplicates: \t" + resourceFileReader.filecounter.DuplicateFiles;
                textBoxMusix.Text = ""; 
                textBoxMovies.Text = "";
                textBoxScanned.Text = resourceFileReader.filecounter.TotalFileCount.ToString();
         
            }
            finally
            {
                resourceFileReader.Dispose();
            }
        }


        private void button1_Click(object sender, EventArgs e)
        {
            ResourceFileReader resourceFileReader = new ResourceFileReader(textBoxMusix, textBoxMovies, textBoxPictures, textBoxScanned, label6, progressBar1, pictureBox1, treeView1);
            try
            {
                treeView1.Nodes.Clear();
                resourceFileReader.CountFiles(treeView1.Nodes.Add(textBox1.Text, textBox1.Text));

                textBoxPictures.Text = resourceFileReader.filecounter.PictureFiles.ToString() + " Files\t" + (resourceFileReader.filecounter.PicturesSize / (1024 * 1024)) + " Mb";
                textBoxMusix.Text = resourceFileReader.filecounter.MusicFiles.ToString() + " Files\t" + (resourceFileReader.filecounter.MusicSize / (1024 * 1024)) + " Mb";
                textBoxMovies.Text = resourceFileReader.filecounter.MovieFiles.ToString() + " Files\t" + (resourceFileReader.filecounter.MovieSize / (1024 * 1024)) + " Mb";
                textBoxScanned.Text = resourceFileReader.filecounter.TotalFileCount.ToString() + " Files\t" + (resourceFileReader.filecounter.TotalSize / (1024 * 1024)) + " Mb";
                
            }
            finally
            {
                resourceFileReader.Dispose();
            }
            MessageBox.Show("Ready.");        
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            PerformScan(treeView1.Nodes[0]);
            MessageBox.Show("Ready.");            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            textBox1.Text = folderBrowserDialog1.SelectedPath; 
        }

        private void button4_Click(object sender, EventArgs e)
        {
            folderBrowserDialog2.ShowDialog();
            textBox2.Text = folderBrowserDialog1.SelectedPath; 

        }

        
    }
}